<%-- 
    Document   : sendMail
    Created on : Nov 5, 2012, 3:07:19 PM
    Author     : Prashanth
--%>

<%@page import="edu.uta.tsrh.RoleManagement.Helper.MailHelper"%>
<%@page import="edu.uta.tsrh.db.MySQLDBServices"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>

<%
  
    try{
        String to = request.getParameter("email");
	String password = request.getParameter("password");
        String username = request.getParameter("username");
	
	String subject = "Auto Generated Password for TSRH";
	String content = "Hi, \n  This is your new password \n "
			 + "Password: " + password;
	//Send the message        
        MailHelper mailHelper = new MailHelper(to, subject, content);
      
	
        
        //forgotPassword ob1 = new forgotPassword();
        
        MySQLDBServices dbservices = new MySQLDBServices();
        int flag = dbservices.forgotPassword(username,to,password);
        
        HttpSession session1 = request.getSession();
        
        if(flag==0)
        {
        session1.setAttribute("forgot", "False");
                     
        response.sendRedirect("emailUser.jsp");
        }
        
        else
       {
                 
        session1.setAttribute("forgot", "True");
          mailHelper.sendMail(); 
        response.sendRedirect("emailUser.jsp");
       }
	//out.println("done my man!!");
     }
    catch(Exception e) 
    { 
        
        response.sendRedirect("emailUser.jsp");
    }
    
        
%>
<b><font color="green">Check your E-mail for the password</font></b>
</body>
</html>